package com.mobileares.midp.widgets.client.frame;

import com.google.gwt.user.client.ui.*;
import com.mobileares.midp.widgets.client.common.DecorateBar;
import com.mobileares.midp.widgets.client.menu.BaseMenuItem;
import com.mobileares.midp.widgets.client.menu.BriefMenu;
import com.mobileares.midp.widgets.client.panel.DecoratePanel;
import com.mobileares.midp.widgets.client.tree.CTree;
import com.mobileares.midp.widgets.client.tree.CTreeItem;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-3-17
 * Time: 9:53:17
 * To change this template use File | Settings | File Templates.
 */
public class MainPanel extends Composite {
    private FlowPanel main;
   SimplePanel body;
//    private DecoratePanel content;
//    private DecoratePanel sideBar;
//    private DecoratePanel menuBar;
    private FlowPanel leftContainer;
    private FlowPanel wrapper;
     DecoratePanel menuContainer;
     DecoratePanel bodyContainer;

    public void setMainWidget(Widget widget) {
        bodyContainer.addWidget(widget);
    }

//    void setMainHeight(int height) {
//        body.setHeight(height - 10 + "px");
//        menuContainer.setHeight(height - 10 + "px");
//    }

    public MainPanel() {
        main = new FlowPanel();
        initWidget(main);
        init();
    }

//    public void setSideBarWidget(Widget widget) {
//        sideBar.addWidget(widget);
//    }
//
//    public void setMenuBarWidget(Widget widget) {
//        menuBar.addWidget(widget);
//    }

    private void init() {

        initMenu();
        main.add(leftContainer);
        main.add(getMain());
        Label clear = new Label();
        clear.setStyleName("clearfloat");
        main.add(clear);


    }

    private Widget getMain() {
        wrapper = new FlowPanel();
        wrapper.setStyleName("frame-main-content");
        DecorateBar top = new DecorateBar("frame-main-top");
        body = new SimplePanel();
//        body.setHeight("100%");
        bodyContainer = new DecoratePanel();
        body.setWidget(bodyContainer);

        DecorateBar bottom = new DecorateBar("frame-main-bottom");
        body.setStyleName("frame-main-body");
        wrapper.add(top);
        wrapper.add(body);
        wrapper.add(bottom);
//        body.setWidget(getContent());
        return wrapper;
    }

    private void initMenu() {
//        sideBar = new DecoratePanel();
//        sideBar.addWidget(new Label("第一个Menu栏"));
//        sideBar.addWidget(initSideBar());

//        SimplePanel split = new SimplePanel();
//        split.setSize("200px", "3px");

//        menuBar = new DecoratePanel();
//        menuBar.addWidget(initSideBar2());

        leftContainer = new FlowPanel();
        leftContainer.setStyleName("frame-main-menu");

        DecorateBar top = new DecorateBar("frame-main-top");
        SimplePanel body = new SimplePanel();
        body.setStyleName("frame-main-body");
//        menu.setHeight("100%");
        menuContainer = new DecoratePanel();
        body.setWidget(menuContainer);


        DecorateBar bottom = new DecorateBar("frame-main-bottom");

        leftContainer.add(top);
        leftContainer.add(body);
        leftContainer.add(bottom);
//        leftContainer.add(sideBar);
//        leftContainer.add(split);
//        leftContainer.add(menuBar);
    }

    public void addMenuWidget(Widget widget) {
        menuContainer.addWidget(widget);
    }
//    public void menuClear() {
//        leftContainer.clear();
//    }

    private Widget initSideBar() {
        //todo:
        BriefMenu menu = new BriefMenu();
        BaseMenuItem item1 = new BaseMenuItem("创建业务");
        BaseMenuItem item2 = new BaseMenuItem("创建公告");
        BaseMenuItem item3 = new BaseMenuItem("报表管理");
        menu.addMenuItem(item1);
        menu.addMenuItem(item2);
        menu.addMenuItem(item3);
        return menu;
    }

    private Widget initSideBar2() {
        CTree tree = new CTree();
        CTreeItem item1 = new CTreeItem("资讯类应用");
        CTreeItem item2 = new CTreeItem("系统管理");
        CTreeItem item3 = new CTreeItem("用户管理");
        CTreeItem item4 = new CTreeItem("榜单管理");
        CTreeItem item5 = new CTreeItem("计费管理");
        CTreeItem item6 = new CTreeItem("订购用户管理");
        CTreeItem item7 = new CTreeItem("报表管理");

        item7.addTreeItem(new CTreeItem("刊物访问次数"));
        item7.addTreeItem(new CTreeItem("刊物订购用户"));
        item7.addTreeItem(new CTreeItem("文章阅读排名"));
        item7.addTreeItem(new CTreeItem("刊物分类排名"));
        item7.addTreeItem(new CTreeItem("刊物阅读用户数"));

//        item6.addTreeItem(item7);

        tree.addTreeItem(item1);
        tree.addTreeItem(item2);
        tree.addTreeItem(item3);
        tree.addTreeItem(item4);
        tree.addTreeItem(item5);
        tree.addTreeItem(item6);
        tree.addTreeItem(item7);
        return tree;

    }

//    private Widget getContent() {
//        FlowPanel wrapper = new FlowPanel();
//        wrapper.setStyleName("frame-main-content");
//        content = new DecoratePanel();
//        wrapper.add(content);
//        return wrapper;
//    }

}
